package com.c6906.vdam.das.schedule;

import cn.hutool.core.date.DateUtil;
import com.c6906.vdam.das.config.DasOpenStatus;
import com.c6906.vdam.das.service.AlarmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@EnableConfigurationProperties({DasOpenStatus.class})
public class UnauthTaskAnalysis {

    public static final Logger logger = LoggerFactory.getLogger(UnauthTaskAnalysis.class);

    @Resource
    DasOpenStatus openStatus;
    @Resource
    AlarmService alarmService;

    /**
     * 05:00 擅自改变出行线路,在应用定时任务之后
     */
    @Scheduled(cron = "0 0 5 * * *")
    public void analysisUnauthTask() {
        if (openStatus.isOpenStatus() && openStatus.isOpenLastGpsToRedis()) {
            logger.info("【擅自改变出行线路】开始执行定时任务......");
            String date = DateUtil.formatDate(DateUtil.offsetDay(DateUtil.date(), -3));
            alarmService.analyzeUnauthTask(date);
            logger.info("【擅自改变出行线路】结束执行定时任务......");
        }
    }
}
